<!--
@license
Copyright 2017 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../../../tf-imports/polymer.html">
<link rel="import" href="../../../paper-checkbox/paper-checkbox.html">
<link rel="import" href="../../../paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="../../../paper-listbox/paper-listbox.html">
<link rel="import" href="../../../paper-input/paper-input.html">
<link rel="import" href="../../../paper-item/paper-item.html">
<link rel="import" href="../../common/common_bundle.html">
<link rel="import" href="../facets-overview-table/facets-overview-table.html">
<link rel="import" href="./facets-overview-filter-validator.html">

<dom-module id='facets-overview'>
  <template>
    <style>
      :host {
        @apply --paper-font-common-base
        font-size: 10pt;
      }
      .controls {
        background: rgba(234,234,234,0.2);
        border-bottom: solid 0.5px rgba(0,0,0,0.2);
        display: flex;
        height: 60px;
        padding-left: 20px;

      }
      .feature-checkboxes {
        background: rgba(234,234,234,0.2);
        border-bottom: solid 0.5px rgba(0,0,0,0.2);
        display: flex;
        flex-wrap: wrap;
        padding:  8px 0 8px 20px;
      }
      .feature-checkbox {
        display: flex;
        padding: 0 0 0 16px;
      }
      paper-checkbox {
        font-size: 14px;
      }
      .input-control {
        --paper-input-container-label --paper-input-container-input: {
          font-size: 14px;
        };
      }
      .features-text {
        line-height: 1;
        padding: 1px 0 0 0;
        font-size: 14px;
      }
      .left-dropdown {
        padding: 0 10px 0 0;
      }
      .middle-checkbox {
        margin-top: 30px;
        padding: 0 10px;
      }
      .right-input {
        width: 300px;
        padding: 0 10px;
      }
      .feature-iron-list {
        max-height: 800px;
        overflow: auto;
      }
      .feature-column {
        width: 200px;
        max-width: 200px;
        overflow-wrap: break-word;
        text-align: left;
      }
      .legend-column {
        width: 120px;
      }
      .stats-column {
        width: 150px;
        max-width: 150px;
        overflow-wrap: break-word;
        text-align: right;
      }
      .chart-column {
        width: 580px;
        text-align: center;
      }
      .table-row {
        display: table-row;
      }
      .table-cell {
        display: table-cell;
        vertical-align: top;
        padding: 10px 5px 0
      }
      .chart-column.table-cell {
        display: table-cell;
        vertical-align: top;
        padding: 10px 0 0 20px
      }
      .header-row {
        clear: both;
      }
      .header-row > .table-cell {
        font-size: 14pt;
        padding: 0 5px 0;
        border-bottom: 1px solid black;
      }
      .stats-header-text {
        text-align: right;
      }
      .chart-header-text {
        text-align: center;
      }
      .table-holder {
        display: flex;
        flex-wrap: wrap;
        overflow-x: auto;
        margin-left: 30px;
      }
      .table-left {
        margin: 20px 20px 0 0;
      }
      .table-right {
        margin: 20px 0 0 0;
      }
      .hidden {
        display: none;
      }
      .legend-holder {
        display: flex;
        flex-wrap: wrap;
        margin: 8px 0 0 38px;
      }
      .legend-box {
        width: 8px;
        height: 8px;
        margin-top: 6px;
      }
      .legend-row {
        display: flex;
      }
      .legend-name {
        margin: 3px 10px 0 5px;
        font-size: 12px;
      }
      /* Give min height to placeholder in paper-input to get around colab embedding
       * alignment issue.
       */
      :host paper-input-container > .floated-label-placeholder {
        min-height: 20px;
      }
    </style>
    <template is="dom-if" if="[[_dataModel]]">
      <div class$="[[_getControlsWrapperClass(_dataModel)]]">
        <div class="controls">
          <paper-dropdown-menu class="left-dropdown input-control" label="Sort by">
            <paper-listbox class="dropdown-content" selected="{{_sortOrder}}" slot="dropdown-content">
              <template is="dom-repeat" items="[[_sortOptions]]" as="option">
                <paper-item>[[option.name]]</paper-item>
              </template>
            </paper-listbox>
          </paper-dropdown-menu>
          <paper-checkbox noink class="middle-checkbox" checked="{{_reverseOrder}}">
            Reverse order
          </paper-checkbox>
          <paper-input class="right-input input-control"
                       label="Feature search (regex enabled)"
                       value="{{searchString}}"
                       auto-validate="true"
                       validator="filter-validator">
            <facets-overview-filter-validator validator-name="filter-validator">
            </facets-overview-filter-validator>
          </paper-input>
        </div>
        <div class="feature-checkboxes">
          <div class="features-text">Features: </div>
          <template is="dom-repeat" items="[[_featureSpecArray]]" as="specAndList">
          <div>
            <paper-checkbox noink checked="true" class="feature-checkbox"
                            id="[[_getSpecCheckboxId(specAndList)]]" on-change="_featureSpecCheck">
              [[_getSpecCheckboxText(specAndList)]]
            </paper-checkbox>
          </div>
        </template>
        </div>
      </div>
      <template is="dom-if" if="[[_hasMultipleDatasets(_dataModel)]]">
        <div class="legend-holder">
          <template is="dom-repeat" items="[[_getDatasets(_dataModel)]]" as="dataset" index-as="datasetIndex">
            <div class="legend-row">
                <paper-checkbox noink checked="true" class="feature-checkbox"
                                style="[[_getLegendBoxStyle(_dataModel, datasetIndex)]]"
                                id="[[_getDatasetId(datasetIndex)]]" on-change="_datasetCheck">
                                [[_getDatasetName(_dataModel, datasetIndex)]]
                </paper-checkbox>
            </div>
          </template>
        </div>
      </template>
      <div class=table-holder>
        <facets-overview-table features="[[_getNumericFeatureListItems(_dataModel, searchString, _sortOrder, _reverseOrder, _featureSpecCheckboxes)]]"
                         data-model="[[_dataModel]]" feature-slice-selection="{{featureSliceSelection}}"
                         dataset-checkboxes="[[_datasetCheckboxes]]"
                         numeric="true" class="table-left" compare-mode="[[compareMode]]">
        </facets-overview-table>
        <facets-overview-table features="[[_getNonNumericFeatureListItems(_dataModel, searchString, _sortOrder, _reverseOrder, _featureSpecCheckboxes)]]"
                         data-model="[[_dataModel]]" feature-slice-selection="{{featureSliceSelection}}"
                         dataset-checkboxes="[[_datasetCheckboxes]]"
                         class="table-right" compare-mode="[[compareMode]]">
        </facets-overview-table>
      </div>
    </template>
  </template>
</dom-module>
<script src="facets-overview.js"></script>
